﻿package Cain.mk
{
	import flash.display.DisplayObject;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.TimerEvent;
	import flash.utils.getDefinitionByName;
	import flash.utils.Timer;
	import Cain.arr_acc;
	import Cain.mk.Lightbox;
	/**
	 * ...
	 * @author Cain@2009 in ADCAST
	 */
	public class LightboxList extends Sprite
	{
		private var pcx:Sprite;
		private var pcx_arr:Array;
		private var chn_time:Number;
		private var ca_height:Number;
		private var fun_time:Number;
		private var fun_wait_time:Number;
		private var ww:Number;
		private var hh:Number;
		private var now_mc:DisplayObject;
		private var lo:Lightbox;
		private var timer:Timer;
		public function LightboxList(_pcx:Sprite, _pcx_arr:Array, _chn_time:Number=3,_ca_height:Number = 20, _fun_time:Number = 1, _fun_wait_time:Number = 0.1) 
		{
			pcx = _pcx;
			pcx_arr = _pcx_arr;
			chn_time = _chn_time;
			ca_height = _ca_height;
			fun_time = _fun_time;
			fun_wait_time = _fun_wait_time;
			init();
		}
		
		private function init():void
		{
			pcx_init();
			timer = new Timer(chn_time * 1000,1);
			timer.addEventListener(TimerEvent.TIMER, lochn);
			timer.start();
		}
		
		private function pcx_init():void
		{
			var mc:DisplayObject = re_class();
			pcx.addChild(mc);
			ww = mc.width;
			hh = mc.height;
			now_mc = mc;
		}
		
		private function re_class():DisplayObject
		{
			var pcx2_class:Class = getDefinitionByName(pcx_arr[0]) as Class;
			var pcx2_mc = new pcx2_class();
			return pcx2_mc as DisplayObject;
		}
		
		private function lochn(e:TimerEvent):void 
		{
			lo = new Lightbox(now_mc, pcx_arr[1], ca_height, fun_time, fun_wait_time);
			lo.addEventListener("end", next);
		}
		
		private function next(e:Event):void 
		{
			now_mc = lo.next_pcx;
			pcx_arr = arr_acc.l_move(pcx_arr);
			timer.start();
		}
	}
	
}